<template>
	<view class="wallet">
		<view class="message_top">
			<view class="message_top_title" :style="{top:computedTop}">我的账户</view>
			<view class="message_top_back" :style="{top:computedTop}" @click="Back">
				<image src="../../static/search/back.png" class="bfbimages"></image>
			</view>
		</view>

		<view class="wallet_one">

			<view>
				<view>
					<text>账户余额</text><br />
					<text style="font-weight: bold;font-size: 60rpx;color: #FFFFFF;">{{MxiTop.balance}}</text>
				</view>
				<view>
					<view @click="Ccz">充值</view>
					<view @click="Ctx">提现</view>
				</view>
			</view>

			<view>
				<view>
					<text>已提现(元)</text><br />
					<text style="font-weight: bold;font-size: 40rpx;color: #FFFFFF;">{{MxiTop.total_withdraw}}</text>
				</view>
				<view>
					<text style="display: inline-block;margin-left: 25rpx;">累计收入(元)</text><br />
					<text
						style="font-weight: bold;font-size: 40rpx;color: #FFFFFF;display: inline-block;margin-left: 25rpx;">{{MxiTop.total_income}}</text>
				</view>
			</view>

		</view>

		<view class="wallet_two">
			<text>账户明细</text>
			<view>
				<view @click="Ctype">
					<text>{{typename?`${typename}`:'全部'}}</text>
					<view class="flex">
						<image src="../../static/my/hui_sanjiao.png" class="bfbimages"></image>
					</view>
				</view>
				<view style="margin-left: 18rpx;" @click="Cdate">
					<text :style="{color:date?'#333333':'#A8A7AA'}">
						{{date?`${date}`:'请选择'}}
					</text>
					<view class="flex">
						<image src="../../static/my/hui_sanjiao.png" class="bfbimages"></image>
					</view>
				</view>
			</view>
		</view>

		<view class="wallet_therr">
			<view v-for="(item,index) in MxiList" :key="index">
				<text style="display: inline-block;margin-top: 15rpx;">{{item.title}}</text>
				<view>
					<text>{{item.create_time}}</text>
					<text style="color: #333333;font-size: 32rpx;" v-if="item.type=='1'">+{{item.amount}}</text>
					<text style="color: #FF4E4E;font-size: 32rpx;" v-else>-{{item.amount}}</text>
				</view>
			</view>
			<view style="width: 100%;height: 150rpx;text-align: center;line-height: 150rpx;color: #999999;font-size: 28rpx;">没有更多啦~</view>
		</view>

		<u-picker :show="show" :columns="columns" @cancel='show=false' @confirm='confirm'></u-picker>

		<u-datetime-picker :show="show1" v-model="value1" mode="date" :formatter="formatter" @cancel='show1=false'
			@confirm='confirmdate'></u-datetime-picker>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				menuButtonInfo: null,
				MxiTop: '',
				type: 0,
				page: 1,
				date: '',
				show: false,
				show1: false,
				columns: [
					['全部', '收入', '支出']
				],
				typename:'',
				value1: Number(new Date()),
				MxiList:''
			}
		},
		computed: {
			computedTop() {
				if (this.menuButtonInfo) {
					return `${this.menuButtonInfo.height * 2 - 6}px`;
				}
				return '0px';
			},
		},
		onLoad() {
			const info = uni.getMenuButtonBoundingClientRect();
			this.menuButtonInfo = info;
		},
		onShow() {
			this.MxiApi()
			this.MxiListApi()
		},
		onReachBottom() {
			this.page++
			let data = {
				type: this.type,
				page: this.page,
				date: this.date
			}
			this.$request('/api/user/getMemberBill', data).then((res) => {
				// this.ShangJiaList = this.ShangJiaList.concat(res.data.data);
				this.$forceUpdate()
			})
		},
		methods: {
			confirmdate(e) {
				const timestamp = e.value;
				const date = new Date(timestamp);
				const year = date.getFullYear();
				const month = String(date.getMonth() + 1).padStart(2, '0'); // 月份从0开始，所以需要加1  
				const day = String(date.getDate()).padStart(2, '0');
				const formattedDate = `${year}-${month}-${day}`;
				console.log(formattedDate, '选择的时间');
				this.date = formattedDate
				this.show1=false
				this.MxiListApi()
			},
			formatter(type, value) {
				if (type === 'year') {
					return `${value}年`
				}
				if (type === 'month') {
					return `${value}月`
				}
				if (type === 'day') {
					return `${value}日`
				}
				return value
			},
			Cdate() {
				this.show1 = true
			},
			confirm(e) {
				console.log(e.value[0]);
				this.typename=e.value[0]

				// 0=全部,1=收入,2=支出
				if (e.value[0] == '全部') {
					this.type = 0
				} else if (e.value[0] == '收入') {
					this.type = 1
				} else {
					this.type = 2
				}
				this.page = 1
				this.MxiListApi()
				this.show=false
			},
			Ctype() {
				this.show = true
			},
			MxiListApi() {
				let data = {
					type: this.type,
					page: this.page,
					date: this.date
				}
				this.$request('/api/user/getMemberBill', data).then((res => {
					console.log(res.data.data, '明细列表');
					this.MxiList=res.data.data
				}))
			},
			MxiApi() {
				this.$request('/api/user/userAmountItem').then((res) => {
					this.MxiTop = res.data
				})
			},
			Ccz() {
				console.log('点击了充值');
				uni.navigateTo({
					url: '/pages/Recharge/Recharge'
				})
			},
			Ctx() {
				console.log('点击了提现');
				uni.navigateTo({
					url: '/pages/Withdrawal/Withdrawal'
				})
			},
			Back() {
				uni.navigateBack()
			}
		}
	}
</script>

<style lang="scss">
	.wallet {
		width: 100vw;
		min-height: 100vh;
		float: left;
		background-color: #F6F8FB;

		.message_top {
			width: 100%;
			height: 200rpx;
			position: relative;

			.message_top_title {
				width: 100%;
				text-align: center;
				font-family: PingFang SC, PingFang SC;
				font-weight: bold;
				font-size: 36rpx;
				color: #333333;
				position: absolute;
				left: 0;
				z-index: 2;
			}

			.message_top_back {
				width: 44rpx;
				height: 44rpx;
				position: absolute;
				left: 30rpx;
				z-index: 9;
			}
		}

		.wallet_one {
			width: 690rpx;
			background: linear-gradient(270deg, #FE4624 0%, #FF8143 100%);
			border-radius: 20rpx;
			margin: 15rpx auto 0;
			padding-top: 60rpx;
			padding-bottom: 50rpx;
		}

		.wallet_one>view:nth-child(1) {
			width: 630rpx;
			height: 100rpx;
			margin: 0 auto;
			display: flex;
			align-items: center;
			justify-content: space-between;
		}

		.wallet_one>view:nth-child(1)>view:nth-child(1) {
			width: 45%;
			height: 100%;
			font-family: PingFang SC, PingFang SC;
			font-weight: 500;
			font-size: 28rpx;
			color: #FFFFFF;
		}

		.wallet_one>view:nth-child(1)>view:nth-child(2) {
			width: 55%;
			height: 100%;
			display: flex;
			align-items: center;
			justify-content: flex-end;
			font-family: PingFang SC, PingFang SC;
			font-weight: 500;
			font-size: 28rpx;
			color: #FFFFFF;
		}

		.wallet_one>view:nth-child(1)>view:nth-child(2)>view {
			width: 150rpx;
			height: 64rpx;
			border-radius: 34rpx;
			border: 1rpx solid #FFFFFF;
			text-align: center;
			line-height: 64rpx;
		}

		.wallet_one>view:nth-child(1)>view:nth-child(2)>view:nth-child(2) {
			background-color: #FFFFFF;
			color: #FE4624;
			margin-left: 40rpx;
		}

		.wallet_one>view:nth-child(2) {
			width: 630rpx;
			height: 85rpx;
			display: flex;
			align-items: center;
			margin: 57rpx auto 0;

		}

		.wallet_one>view:nth-child(2)>view {
			width: 50%;
			height: 100%;
			font-family: PingFang SC, PingFang SC;
			font-weight: 400;
			font-size: 24rpx;
			color: #FFFFFF;
		}

		.wallet_two {
			width: 690rpx;
			height: 68rpx;
			margin: 30rpx auto 0;
			display: flex;
			align-items: center;
			justify-content: space-between;
			font-family: PingFang SC, PingFang SC;
			font-weight: 500;
			font-size: 32rpx;
			color: #1E1E1E;
		}

		.wallet_two>view {
			display: flex;
			align-items: center;
			justify-content: flex-end;
			font-family: PingFang SC, PingFang SC;
			font-weight: 400;
			font-size: 24rpx;
			color: #0E0E0E;
		}

		.wallet_two>view>view {
			min-width: 168rpx;
			max-width: 270rpx;
			height: 68rpx;
			background: #FFFFFF;
			border-radius: 34rpx;
			display: flex;
			align-items: center;
			justify-content: center;
		}

		.wallet_two>view>view>view {
			width: 18rpx;
			height: 10rpx;
			text-align: center;
			line-height: 10rpx;
			margin-left: 20rpx;
		}

		.wallet_therr {
			width: 690rpx;
			background: #FFFFFF;
			border-radius: 20rpx;
			margin: 20rpx auto 0;
			padding-top: 20rpx;
			padding-bottom: 20rpx;
		}

		.wallet_therr>view {
			width: 630rpx;
			height: 134rpx;
			border-bottom: 2rpx solid #ECECEC;
			padding-left: 30rpx;
			padding-right: 30rpx;
			font-family: PingFang SC, PingFang SC;
			font-weight: 500;
			font-size: 28rpx;
			color: #1E1E1E;
		}

		.wallet_therr>view:last-child {
			border: 0;
		}

		.wallet_therr>view>view {
			display: flex;
			align-items: center;
			justify-content: space-between;
			font-family: PingFang SC, PingFang SC;
			font-weight: 400;
			font-size: 24rpx;
			color: #969696;
			width: 100%;
			height: 30rpx;
			margin-top: 20rpx;
		}
	}
</style>